package yiran.stock;

import net.milkbowl.vault.economy.Economy;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import yiran.stock.output.Logger;

public class EconomyManager {
    private final JavaPlugin plugin;
    private Economy economy;
    
    public EconomyManager(JavaPlugin plugin) {
        this.plugin = plugin;
    }
    
    public void setupEconomy() {
        if (plugin.getServer().getPluginManager().getPlugin("Vault") == null) {
            Logger.error("未找到Vault插件，经济功能将不可用！");
            return;
        }

        RegisteredServiceProvider<Economy> rsp = plugin.getServer().getServicesManager().getRegistration(Economy.class);
        if (rsp == null) {
            Logger.error("未找到可用的经济系统提供者，请安装经济插件如EssentialsX！");
            return;
        }

        economy = rsp.getProvider();
        Logger.info("已连接经济系统: " + economy.getName());
    }

    public Economy getEconomy() {
        return economy;
    }

    public boolean isEconomyEnabled() {
        return economy != null;
    }
}
